﻿using System.Linq;
using System.Web.Mvc;
using QDT.Common;
using QDT.Core.Assignments;
using QDT.Core.Experience;
using QDT.Core.Projects;
using QDT.Web.Code;

namespace QDT.Web.Controllers
{

    public partial class WidgetController
    {

        public PartialViewResult Projects(object proPagedList, int? num = 4)
        {
            var othermodel = proPagedList as IPagedList<Project>;
            if (othermodel != null)
            {
                return PartialView(othermodel.ToPagedList(0, 8));
            }

            int intWait = (int)ProjectStatus.Wait;

            int intBad = (int)ProjectStatus.Bad;

            var filter = PredicateExtensionses.True<Project>();

            filter = filter.And(x => x.TypeID != 7);

            var module = DbProvider.D<Project>()
                                   .Where(
                                       filter.And(
                                           x =>
                                           !x.IsDelete && x.IsEffect && x.InnerStatus != intWait &&
                                           x.InnerStatus != intBad && !x.IsOffline))
                                   .OrderBy(x => x.InnerStatus).ThenByDescending(x => x.ID).ToPagedList(0, num ?? 4);


            return ChildResult(module);
        }
        public PartialViewResult Assigns(int? num = 5)
        {

            var filter = PredicateExtensionses.True<Assignment>();

            var module = DbProvider.D<Assignment>()
                                   .Where(
                                       filter.And(
                                           x => !x.IsDelete && x.IsEffect && !x.IsOffline))
                                   .OrderBy(x => x.InnerStatus).ThenByDescending(x => x.ID).ToPagedList(0, num ?? 5);

            return ChildResult(module);
        }

        public PartialViewResult AgencyProjects(int agencyId, int? num = 5)
        {

            int intWait = (int)ProjectStatus.Wait;

            int intBad = (int)ProjectStatus.Bad;

            var filter = PredicateExtensionses.True<Project>();

            filter = filter.And(x => x.TypeID != 7);

            var module = DbProvider.D<Project>()
                                   .Where(
                                       filter.And(
                                           x => x.Parent.AgencyId == agencyId &&
                                           !x.IsDelete && x.IsEffect && x.InnerStatus != intWait &&
                                           x.InnerStatus != intBad && !x.IsOffline))
                                   .OrderBy(x => x.InnerStatus).ThenByDescending(x => x.ID).ToPagedList(0, num ?? 5);

            return ChildResult("Projects", module);
        }
        public PartialViewResult Experience(object expPagedList, int? num = 1, bool isVip = false)
        {
            var pagelist = expPagedList as IPagedList<ExpProject>;
            var filter = PredicateExtensionses.True<ExpProject>().And(x => x.Status != 0);
            if (pagelist != null)
            {
                return PartialView(pagelist.ToPagedList(0, 8));
            }
            var expproject = DbProvider.D<ExpProject>().Where(filter).OrderBy(x => x.Status).ThenByDescending(x => x.ID).ToPagedList(0, num ?? 1);
            return ChildResult(expproject);
        }
    }
}